package com.autonavi.yunda.yunji.common.web.entity;

import com.autonavi.yunda.yunji.common.exception.AmapExceptionCode;
import com.autonavi.yunda.yunji.common.utils.JsonUtils;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author cizhong.wcs
 * @date 2022/1/29 11:19 上午
 */
@Data
@NoArgsConstructor
public class GlobalResponse<T> {
    private int code;
    private String message;
    private T data;

    public static <T> GlobalResponse<T> successResult(T data) {
        GlobalResponse<T> res = new GlobalResponse<>();
        res.code = AmapExceptionCode.COMMON_SERVER_SUCCESS.getCode();
        res.message = AmapExceptionCode.COMMON_SERVER_SUCCESS.getText();
        res.data = data;
        return res;
    }

    public static <T> GlobalResponse<T> errorResult(int code, String message) {
        GlobalResponse<T> res = new GlobalResponse<>();
        res.code = code;
        res.message = message;
        return res;
    }

    @Override
    public String toString() {
        return JsonUtils.toString(this);
    }
}
